<?php

class Myzen_Oauth_Token {
  // access tokens and request tokens
  public $key;
  public $secret;




  /**
   * key = the token
   * secret = the token secret
   */
  function __construct($key, $secret) {
    $this->key = $key;
    $this->secret = $secret;
  }

  /**
   * generates the basic string serialization of a token that a server
   * would respond to request_token and access_token calls with
   */
  function toString() {
    return "oauth_token=" .
           Myzen_OAuth_Util::urlencode_rfc3986($this->key) .
           "&oauth_token_secret=" .
           Myzen_OAuth_Util::urlencode_rfc3986($this->secret);
  }

  function __toString() {
    return $this->toString();
  }
  
  static public function create($tokenType,$consumer,$requestToken = null) {
    if('request' == $tokenType) return Myzen_Oauth_Token_Request::create($consumer);
    if('access' == $tokenType) return Myzen_Oauth_Token_Access::create($consumer,$requestToken);
    throw new Myzen_Oauth_Exception('tokenType not valid');
  } //end create
  
  static public function getToken($tokenType,$tokenKey) {
    if('request' == $tokenType) return new Myzen_Oauth_Token_Request($tokenKey);
    if('access' == $tokenType) return new Myzen_Oauth_Token_Access($tokenKey);    	
    throw new Myzen_Oauth_Exception('tokenType not valid');
  }
  
}
